package com.example.springboot001.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
import java.util.Map;

/**
 * @program: springboot001
 * @description: 自定义视图解析器
 * @author: XianJin.Lu
 * @create: 2021-09-25 21:06
 **/
@Configuration  //使当前这个类变成配置类
//一但表注了@EnableWebMvc，那么MVC将被全面接管
public class MyMvcConfig implements WebMvcConfigurer {

    //public interface ViewResolver 实现了视图解析器接口的类，我们就可以把它看做视图解析器

    /*第二步：将自己写的视图解析器注册到Bean里面，它就会自动帮我们装配上*/
    @Bean
    public ViewResolver MyViewResolver() {
        return new MyViewResolver();
    }

    /*第一步：自定义了一个自己的视图解析器MyViewResolver*/
    public static class MyViewResolver implements ViewResolver {

        @Override
        public View resolveViewName(String viewName, Locale locale) throws Exception {

            /*具体实现网上没找到应该有点复杂*/
            return null;
        }
    }
}
